#!/usr/bin/env node

//rm xyz 命令行删除
const fs = require('fs');
const src = process.argv[2] ?? __filename

// 检查命令行参数是否完整
if (!src) {
    console.error('Usage: node 09-my-rm.js <file>');
    process.exit(1);
}

// 检查文件是否存在
if (!fs.existsSync(src)) {
    console.error('Error: File does not exist.');
    process.exit(1);
}

// 检查是否为文件
if (fs.statSync(src).isFile()) {
    // 删除文件
    fs.unlinkSync(src);
    console.log(`File ${src} has been deleted.`);
} else if (fs.statSync(src).isDirectory()) {
    // 如果是目录，则忽略
    console.log('Error: Directory deletion is not supported by this script.');
} else {
    // 其他类型（如符号链接等）也忽略
    console.log('Error: Only files can be deleted by this script.');
}
